package io.File;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;

public class FileDemo {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\test");
        if(file.isDirectory()){//是否为目录 isDirectory
            //过滤.java文件
            String [] list = file.list( new MyFineNameFilter());//过滤器
            for (String name:list) {
                System.out.println(name);
            }
        }
    }

    private static void test3() {
        File f1 = new File("c:\\java\\apache-tomcat-8.5.57");
        if (f1.isDirectory()){
            String [] names = f1.list();
            for (String name:names) {
                System.out.println(name);
            }
        }
    }

    private static void text2() throws IOException {
        File f1 = new File("D:\\code\\abc.java");
        if (f1.exists()) {
                f1.delete();
        }else {
        f1.createNewFile();
    }
    }

    private static void text1() {
       File f1=new File("D:\\test");
       // File f3 = new File(new File("D:\\test"),"one.text");
       // File f2= new File("D:\\test","one.text");
        //File file = new File("file","one.text");
        if (f1.exists()){
            System.out.println("文件存在");
        }else {
            System.out.println("文件不存在");
        }
        System.out.println(f1);
    }
}
class  MyFineNameFilter implements FilenameFilter{
//过滤器
    @Override
    public boolean accept(File file, String s) {
        File f1= new File(file,s);
        if (f1.isFile()&&s.endsWith(".java")){
            return true;
        }else {
            return false;
        }
    }
}